'use strict';
// Declare app level module which depends on views, and components
angular.module('myApp', [
    'ngRoute',
    'myApp.custom',
    'myApp.robot',
    'myApp.weather',
    'myApp.live'
])
    .config(['$locationProvider', '$routeProvider','$sceDelegateProvider',function($locationProvider, $routeProvider,$sceDelegateProvider) {
    $sceDelegateProvider.resourceUrlWhitelist([
        'self',
        'https://cdn.asilu.com/**'
    ]); //域名访问白名单
    $locationProvider.hashPrefix('');
    $routeProvider
        .when('/custom',{templateUrl:'view/custom/view.html',controller: 'ViewCtrl'})
        .when('/robot',{templateUrl:'view/robot/robot.html',controller: 'RobotCtrl'})
        .when('/weather',{templateUrl:'view/weather/weather.html',controller: 'WeatherCtrl'})
        .when('/live',{templateUrl:'view/live/live.html',controller: 'LiveCtrl'})
        .otherwise({redirectTo: '/'});
}])
    .controller('myCtrl',function ($scope,$location,$rootScope){
        jQuery.ajax({
            type:'post',
            contentType: "application/json; charset=utf-8",
            dataType:'jsonp',
            url:'https://api.asilu.com/geo/',
            success:function (data){
                $rootScope.address=data.address;
                $rootScope.url=data.url;
                $rootScope.$apply();
            }
        });
        $rootScope.nav=[
            {"uri":"#/","title":"首页","select":null},
            {"uri":"#/custom","title":"数据","select":null},
            {"uri":"#/robot","title":"图灵","select":null},
            {"uri":"#/weather","title":"天气","select":null},
            {"uri":"#/live","title":"直播","select":null}
        ];
        $rootScope.$on('$routeChangeSuccess', function (e, next, current) {
                $rootScope.nav.forEach(function (value) {
                    if ($location.path() == value.uri.substr(1)){
                            value.select = 'select';
                    } else {
                            value.select = '';
                    }
                });
            });//路由跳转事件
        $rootScope.$on('$routeChangeStart', function (e, next, current) {
            $rootScope.nav.forEach(function (value) {
                if ($location.path() == '/'){
                    $rootScope.isIndex = true;
                } else {
                    $rootScope.isIndex = false;
                }
            });
        });
        $scope.isShow=false;
        $scope.showNav=function () {
            $scope.isShow = !$scope.isShow;

        }
        $scope.hideNav=function () {
            $scope.isShow = false;
        }
    });

